<template>
  <div style="min-height: 100%">
    <!--    头部-->
    <div class="header">
      <div
        style="
          width: 300px;
          display: flex;
          align-items: center;
          justify-content: center;
          margin-right: 50px;
        "
      >
        <img src="../../assets/logo1.png" alt="" style="width: 50px" />
        <span style="margin-left: 10px">乡镇农业产品信息平台</span>
      </div>
      <div style="flex: 2">
        <!--        导航菜单-->
        <!--        <ul style="list-style: none; background-color: palegreen">-->
        <!--          <li class="item">-->
        <!--            <el-dropdown size="medium">-->
        <!--              <span>更多菜单<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i></span>-->
        <!--              <el-dropdown-menu slot="dropdown">-->
        <!--                <el-dropdown-item><i class="el-icon-plus"></i>黄金糕</el-dropdown-item>-->
        <!--                <el-dropdown-item>狮子头</el-dropdown-item>-->
        <!--                <el-dropdown-item>螺蛳粉</el-dropdown-item>-->
        <!--                <el-dropdown-item>双皮奶</el-dropdown-item>-->
        <!--                <el-dropdown-item>蚵仔煎</el-dropdown-item>-->
        <!--              </el-dropdown-menu>-->
        <!--            </el-dropdown>-->
        <!--          </li>-->
        <!--          <li class="item"><router-link to="">菜单2</router-link></li>-->
        <!--          <li class="item"><router-link to="">菜单3</router-link></li>-->
        <!--          <li class="item"><router-link to="">菜单4</router-link></li>-->
        <!--        </ul>-->

        <el-menu
          :default-active="$route.path"
          class="el-menu-demo"
          mode="horizontal"
          router
        >
          <el-menu-item index="/front/home">首页</el-menu-item>
          <el-menu-item index="/front/goodsList">产物列表</el-menu-item>
          <el-menu-item index="/front/person">个人信息</el-menu-item>
          <!-- <el-submenu index="2">
            <template slot="title">我的工作台</template>
            <el-menu-item index="2-1">选项1</el-menu-item>
            <el-menu-item index="2-2">选项2</el-menu-item>
            <el-menu-item index="2-3">选项3</el-menu-item>
            <el-submenu index="2-4">
              <template slot="title">选项4</template>
              <el-menu-item index="2-4-1">选项1</el-menu-item>
              <el-menu-item index="2-4-2">选项2</el-menu-item>
              <el-menu-item index="2-4-3">选项3</el-menu-item>
            </el-submenu>
          </el-submenu> -->
          <!-- <el-menu-item index="3" disabled>消息中心</el-menu-item>
          <el-menu-item index="4"
            ><a href="https://www.ele.me" target="_blank"
              >订单管理</a
            ></el-menu-item
          > -->
        </el-menu>
      </div>
      <div style="flex: 1">
        <div v-if="!user.name" style="text-align: right; padding-right: 30px">
          <el-button @click="$router.push('/login')">登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else style="text-align: right; padding-right: 30px">
          <el-dropdown style="cursor: pointer; font-size: 18px">
            <div @click="$router.push('/front/person')">
              <img
                :src="user.avatarUrl"
                alt=""
                style="
                  width: 30px;
                  border-radius: 50%;
                  position: relative;
                  top: 8px;
                  right: 5px;
                "
              />
              <span>{{ user.name }} </span>
              <i class="el-icon-arrow-down" style="margin-right: 15px"></i>
            </div>
            <el-dropdown-menu
              slot="dropdown"
              style="width: 100px; text-align: center"
            >
              <el-dropdown-item
                style="font-size: 16px; line-height: 30px"
                @click.native="$router.push('/front/person')"
              >
                个人信息
              </el-dropdown-item>
              <el-dropdown-item
                style="font-size: 16px; line-height: 30px"
                @click.native="logout"
              >
                退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

    <!-- 主体内容 -->
    <div style="min-height: 100%">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import TagsView from '@/components/TagsView.vue'
import Password from '@/components/Password.vue'
import Person from '@/components/Person.vue'

export default {
  name: 'Front',
  components: {
    TagsView,
    Password,
    Person
  },
  data() {
    return {
      user: JSON.parse(localStorage.getItem('curUser')) || {}
    }
  },
  methods: {
    logout() {
      localStorage.removeItem('curUser')
      this.$message.success('退出成功')
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.header {
  display: flex;
  position: absolute;
  width: 100%;
  height: 60px;
  line-height: 60px;
  background-color: rgba(0, 0, 0, 0.8);
  color: #eee !important;
}
.el-menu {
  background-color: transparent;
}
.el-menu.el-menu--horizontal {
  border-bottom: 0;
}
.el-menu--horizontal > .el-menu-item {
  color: #eee;
}
.el-menu--horizontal > .el-menu-item.is-active {
  border-bottom: 0;
  color: #f2d070;
  background-color: rgba(242, 208, 112, 0.1);
}
/* .el-menu--horizontal > .el-menu-item:not(.is-disabled):focus {
  background-color: transparent;
} */
.el-menu--horizontal > .el-menu-item:not(.is-disabled):hover,
.el-menu--horizontal > .el-submenu .el-submenu__title:hover {
  background-color: rgba(242, 208, 112, 0.1);
}
.el-menu--horizontal .el-menu-item:not(.is-disabled):focus,
.el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
  color: #f2d070;
}
.el-dropdown {
  color: #eee;
}
.item {
  display: inline-block;
  width: 100px;
  color: #260aa1;
  text-align: center;
  cursor: pointer;
}
.item a {
  text-decoration: none;
  color: #260aa1;
}
.item:hover {
  background-color: pink;
}
</style>
